package 比屋作业.day14;

public class D14_2 {
    public static void main(String[] args) {
        Dog dog1=new Dog("旺财");
        Dog dog2= new Dog("狗子");
        dog1.sound();
        dog2.sound();
        System.out.println(dog1.equals(dog2));
        Cat cat1=new Cat("小黑");
        Cat cat2=new Cat("小白");
        cat1.sound();
        cat2.sound();
        System.out.println(cat1.equals(cat2));
    }
}
abstract class Animal{
    public abstract void sound();
}
class Dog extends Animal{
    private String name;
    public Dog(String name){
        this.name=name;
    }
    public String getName(){
        return name;
    }
    @Override
    public void sound() {
     StringBuilder sb=new StringBuilder("名字是："+name+"的小狗：");
     sb.append("汪汪汪....");
        System.out.println(sb);
    }
    @Override
    public boolean equals(Object obj) {
        Dog dog=(Dog)obj;
        return this.name.equals(dog.name);
    }
}
class Cat extends Animal{
    private String name;
    public Cat(String name){
        this.name=name;
    }

    @Override
    public void sound() {
        StringBuilder sb=new StringBuilder("名字是："+name+"的小猫：");
        sb.append("喵喵喵....");
        System.out.println(sb);
    }

    @Override
    public boolean equals(Object obj) {
        Cat cat =(Cat) obj;
        return this.name.equals(cat.name);
    }
}
